﻿using BigEgg.Framework.Foundation;
using BigEgg.Framework.UnitTesting;
using FMStudio.Domain.Properties;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Globalization;

namespace FMStudio.Domain.SQLite.Test
{
    [TestClass]
    public class PayTypeTest
    {
        [TestMethod]
        public void GeneralPayTypeTest()
        {
            PayType payType = new PayType();

            Assert.IsNotNull(payType.ID);
            Assert.AreEqual("", payType.Name);
            Assert.IsNull(payType.Currency);

            Currency currency = new Currency();
            payType.Currency = currency;
            payType.Name = "Cash";

            Assert.AreEqual("", payType.Validate());
        }

        [TestMethod]
        public void PayTypeCurrencyPropertyChangedTest()
        {
            PayType payType = new PayType();
            Assert.IsNull(payType.Currency);

            Currency currency = new Currency();
            AssertHelper.PropertyChangedEvent(payType, x => x.Currency, () => payType.Currency = currency);
            Assert.AreEqual(currency, payType.Currency);
        }
        
        [TestMethod]
        public void PayTypeNameValidationTest()
        {
            PayType payType = new PayType();

            Assert.AreEqual(string.Empty, payType.Name);
            Assert.AreEqual(Resources.PayTypeNameMandatory, payType.Validate("Name"));

            payType.Name = TestHelper.CreateString('A', 99);
            Assert.AreEqual("", payType.Validate("Name"));
            payType.Name = TestHelper.CreateString('A', 100);
            Assert.AreEqual("", payType.Validate("Name"));
            payType.Name = TestHelper.CreateString('A', 101);
            Assert.AreEqual(
                string.Format(CultureInfo.CurrentCulture, Resources.PayTypeNameMaxLength, "Name", 100)
                , payType.Validate("Name"));
        }

        [TestMethod]
        public void PayTypeCurrencyValidationTest()
        {
            PayType payType = new PayType();

            Assert.IsNull(payType.Currency);
            Assert.AreEqual(Resources.CurrencyMandatory, payType.Validate("Currency"));

            Currency currency = new Currency();
            payType.Currency = currency;
            Assert.AreEqual("", payType.Validate("Currency"));
        }
    }
}
